<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <input type="text" name="id" id="id" style="display: none"
           class="layui-input">
    <div class="layui-form-item">
        <label class="layui-form-label">数据权限类型:</label>
        <div class="layui-input-inline">
            <select name="powerDataType" id="powerDataType" lay-search="">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限到期时间</label>
        <div class="layui-input-inline">
            <input readonly="readonly" type="text" class="layui-input" name="powerLastTime"
                   id="powerLastTime">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/static/lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
<script src="/static/js/common.js"></script>
<script>
    let powerDataType = $.common.getUrlParam("powerDataType");
    layui.use(['form', 'laydate'], function () {
        var form = layui.form,
            laydate = layui.laydate;

        initPowerDataType();
        //初始化下拉框
        form.render("select");
        //初始化时间
        laydate.render({
            elem: '#powerLastTime'
            , type: 'datetime'
        });


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            let url = "/users/power"
            let callback = {
                onSuccess: function (result) {
                    if (result.code == '0') {
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.location.reload();
                        parent.layer.close(iframeIndex);
                    } else {
                        $.common.showErrorMessage(result.message)
                        return false;
                    }
                }
            };
            $.xAjax(url, 'POST', JSON.stringify(data.field), callback);
            return false;
        });
    });

    function initPowerDataType() {
        let powerDataTypeArray = [
            {"key": "修改", "value": 0},
            {"key": "查看", "value": 1},
            {"key": "无权限", "value": 2}];
        $('#powerDataType').append(new Option('请选择', '', true));// 下拉菜单里添加元素
        $.each(powerDataTypeArray, function (index, item) {
            let option = new Option(item.key, item.value);
            if (powerDataType) {
                if (item.value == powerDataType) {
                    option.selected = true;
                }
            }
            $('#powerDataType').append(option);// 下拉菜单里添加元素
        });
    }
</script>
</body>
</html>
